FROM php:5.6-fpm-alpine

COPY composer.phar /usr/local/bin
COPY cacert.pem /usr/local/etc/php/

RUN set -eux; \
    # composer
    mv /usr/local/bin/composer.phar /usr/local/bin/composer && \
    chmod u+x /usr/local/bin/composer && \
    composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/; \
    # 换源
    sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
    # 依赖
    apk add --no-cache freetype \
    libpng \
    libjpeg-turbo \
    freetype-dev \
    libpng-dev \
    libjpeg-turbo-dev && \
    docker-php-ext-configure gd \
    --with-gd \
    --with-freetype-dir=/usr/include/ \
    --with-png-dir=/usr/include/ \
    --with-jpeg-dir=/usr/include/ && \
    NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) && \
    # 扩展
    docker-php-ext-install -j${NPROC} gd && \
    docker-php-ext-install pdo mysqli zip pdo_mysql bcmath && \
    # 删除没用的
    apk del --no-cache freetype-dev libpng-dev libjpeg-turbo-dev && \
    # 定义一些配置
    cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini && \
    echo 'openssl.cafile=/usr/local/etc/php/cacert.pem' >> /usr/local/etc/php/php.ini && \
    sed -i "s/;always_populate_raw_post_data = -1/always_populate_raw_post_data = -1/g" /usr/local/etc/php/php.ini;